package com.project.nimsen.web.sys;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.project.jdbc.web.BaseMVCAction;
import com.project.nimsen.common.web.LoginUser;
import com.project.nimsen.entity.SUserEntity;
import com.project.nimsen.service.ISUserService;
@Controller
@RequestMapping(value ="/sys/user")
public class SUserControl extends BaseMVCAction {
	@Resource
	ISUserService userService;
	//得到除自己以外的所有信息
	@RequestMapping(value="/uppwd")
	@ResponseBody
	public Map<String, Object> uppwd(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("success", false);
		String oldpw = getRequest().getParameter("oldpw");
		if(StringUtils.isBlank(oldpw)){
			map.put("message", "原密码不可以为空");
			return map;
		}
		String newpw = getParameter("newpw");
		if(StringUtils.isBlank(newpw)){
			map.put("message", "新密码不可以为空");
			return map;
		}
		String repw = getParameter("repw");
		if(StringUtils.isBlank(repw)){
			map.put("message", "确认密码不可以为空");
			return map;
		}
		if(!repw.equals(newpw)){
			map.put("message", "两次输入的密码不一致");
			return map;
		}
		LoginUser cur_user = LoginUser.getCurr();
		try {
			SUserEntity use = userService.findById(cur_user.getUserid());
			if(!oldpw.equals(use.getPass_word())){
				map.put("message", "原密码不正确");
				return map;
			}
			use.setPass_word(newpw);
			if(userService.update(use)>0){
				map.put("success", true);
			}else{
				map.put("message", "修改失败请联第管理员");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
}
